﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using Helper;
using System.ComponentModel;
namespace CoreData
{
    public class Class
    {
       //   [Description("ID")]
            public long ID{get;set;}
        [Description("Mã lớp")]
            public string Code{get;set;}
        [Description("Tên lớp")]
            public string Name{get;set;}
        [Description("Ghi chú")]
            public string Description{get;set;}
        [Description("Ngày tạo")]
        public DateTime CreateDate { get; set; }
    //    [Description(" ")]
            public long CourseID{get;set;}
     //   [Description(" ")]
            public long MainTeacherID{get;set;}
            public long BranchID { get; set; }
        [Description("Học phí")]
            public int Price { get; set; }
        [Description("Ngày khai giảng")]
        public DateTime StartDate { get; set; }
        [Description("Ngày kết thúc")]
        public DateTime EndDate { get; set; }
        public int Type { get; set; }
        [Description("Sĩ số")]
            public int Size{get;set;}
        [Description("Giờ học")]
            public string Study_Time{get;set;}
        [Description("Đã học xong")]
            public bool Active{get;set;}
        public bool IsDeleted { get; set; }
        [Description("Giáo viên chủ nhiệm")]
            public string TeacherExt { get; set; }
        [Description("Khóa")]
            public string CourseExt { get; set; }
        [Description("Ngành")]
        public string BranchExt { get; set; }
        [Description("Loại")]
        public string TypeExt { get; set; }
         

        #region Properties for report

        public int StartClassDayExt { get; set; }
        public int StartClassMonthExt { get; set; } //thang bay đau khai giang lop hoc
        public int StartClassYearExt { get; set; } //năm băt dau khai giang
     
        #endregion

        public Class()
        {       
                            Code ="";   
                            Name ="";   
                            Description ="";   
                          //  MainTeacherID ="";   
                            Study_Time ="";
                            IsDeleted = false;
                            Size = 0;
                            CreateDate = DateTime.Now;
                            Price = 33000000;
                            StartDate = DateTime.Now;
                            EndDate = StartDate.AddMonths(1);
        }
        
       static Class DynamicCast<T>(object row_data, object row_header) where T : Class
       {
           // row_data : DataRow
           // row_header : DataColumnCollection
           Class ret = new Class();
           DataRow dt = (DataRow)row_data;

           foreach (DataColumn column in (DataColumnCollection)row_header)
           {
               switch (column.ColumnName)
               {
                      case  "ID":
                        ret.ID = ConvertObject.ToLong(dt[column]);
                       break;
                      case  "Code":
                        ret.Code = ConvertObject.ToString(dt[column]);
                       break;
                      case  "Name":
                        ret.Name = ConvertObject.ToString(dt[column]);
                       break;
                      case  "Description":
                        ret.Description = ConvertObject.ToString(dt[column]);
                       break;
                      case  "CourseID":
                        ret.CourseID = ConvertObject.ToLong(dt[column]);
                       break;
                      case  "MainTeacherID":
                        ret.MainTeacherID = ConvertObject.ToLong(dt[column]);
                       break;
                   case "BranchID":
                       ret.BranchID = ConvertObject.ToLong(dt[column]);
                       break;
                      case  "Size":
                        ret.Size = ConvertObject.ToInt(dt[column]);
                       break;
                      case  "Study_Time":
                        ret.Study_Time = ConvertObject.ToString(dt[column]);
                       break;
                      case  "Active":
                        ret.Active = ConvertObject.ToBool(dt[column]);
                       break;
                      case "IsDeleted":
                       ret.IsDeleted = ConvertObject.ToBool(dt[column]);
                       break;
                      case "CreateDate":
                       ret.CreateDate = ConvertObject.ToDateTime(dt[column]);
                       break;
                      case "TeacherName":
                       ret.TeacherExt = ConvertObject.ToString(dt[column]);
                       break;
                      case "BranchName":
                       ret.BranchExt = ConvertObject.ToString(dt[column]);
                       break;
                      case "CourseName":
                       ret.CourseExt = ConvertObject.ToString(dt[column]);
                       break;
                      case "StartDate":
                       ret.StartDate = ConvertObject.ToDateTime(dt[column]);
                       ret.StartClassDayExt = ret.StartDate.Day;
                       ret.StartClassYearExt = ret.StartDate.Year;
                       ret.StartClassMonthExt = ret.StartDate.Month;
                       break;
                      case "EndDate":
                       ret.EndDate = ConvertObject.ToDateTime(dt[column]);
                       break;

                      case "Type":
                       {
                           ret.Type = ConvertObject.ToInt(dt[column]);
                           if (ret.Type == 1)
                           {
                               ret.TypeExt = "Chuyên nghiệp";
                           }
                           else
                           {
                               ret.TypeExt = "Ngắn hạn";
                           }
                       }
                       break;
                   case "Price":
                       ret.Price = ConvertObject.ToInt(dt[column]);
                       break;

                  
                   default:
                       break;
               }
           }

           return ret;
       }
        
    }
}
